#ifndef TETRISWIDGET_H
#define TETRISWIDGET_H

/*!
 * \file     tetriswidget.h
 * \brief    Widget of the Tetris game.
 * \author   Duriez Franck
 * \author   Carton Paul-Henri
 * \version  0.1
 */

#include <QKeyEvent>
#include <QApplication>
#include "qsfmlwidget.h"
#include "grid.h"
#include "shape.h"
#include "nextshapemanager.h"
#include "scoremanager.h"

/*!
 * \class TetrisWidget
 * \brief Widget of the Tetris game.
 * \todo Abstract this class and delete inheritence to be independent
 *       towards the graphic library.
 */
class TetrisWidget : public QSFMLWidget /*{{{*/
{
	Q_OBJECT
/*{{{*/
public:
	/*!
	 * \brief Constructor.
	 * \param parent : paretn of the TetrisWidget
	 */
	TetrisWidget(QWidget* parent);

	/*!
	 * \brief Destructor.
	 */
	virtual ~TetrisWidget();

	/*!
	 * \brief Draw all the elements.
	 * \todo  Thread the elements of this function.
	 */
	virtual void draw();

public slots:
	void gameOver();

private:
	bool m_on_pause;                   ///< Pause ?
	bool m_game_over;                  ///< Game over ?
	sf::Image m_background_image;      ///< Global background image
	sf::Sprite m_background_sprite;    ///< Global background sprite
/*}}}*/

	/***************
	 * QSFMLWIDGET *
	 ***************/
/*{{{*/
public:
	void initialize();

	void update();

protected:
	/*!
	 * \brief Here is define keyboard control.
	 *
	 * Keyboard control : \n
	 *   \li \c Shift   : rotate \n
	 *   \li \c Control : antirotate \n
	 *   \li \c Left    : move left \n
	 *   \li \c Right   : move right \n
	 *   \li \c Down    : move down \n
	 *   \li \c Up      : move up (only in DEBUG mode)
	 *   \li \c ESC     : quit
	 */
	void keyPressEvent(QKeyEvent* event);
/*}}}*/

	/********
	 * GRID *
	 ********/
/*{{{*/
public slots:
	void putTheNextShapeInTheGrid();

private:
	Grid m_grid;                       ///< Tetris Grid
	QTimer m_move_down_timer;          ///< Timer for Shape movement
/*}}}*/

	/*********
	 * SHAPE *
	 *********/
/*{{{*/
public slots:
	/*!
	 * \brief Set the interval of TetrisWidget::m_move_down_timer.
	 */
	void setMoveDownSpeed();
/*}}}*/

	/********************
	 * NEXTSHAPEMANAGER *
	 ********************/
private:
	NextShapeManager m_next_shape_manager;
	                                   ///< Next Shape creator and displayer

	/****************
	 * SCOREMANAGER *
	 ****************/
private:
	ScoreManager m_score_manager;      ///< Score displayer and manager
}; /*}}}*/

#endif // TETRISWIDGET_H
